<template>
	<view class="container">
		<!-- 列表 -->
		<zy-cell :cellList="cellList1" :title="$t('my.set.system')" @clickHandler='clickListHandler' />
		<zy-cell :cellList="cellList2" :type="type" @clickHandler='clickGroupHandler' />
		<!-- 版本自动更新弹框 -->
		<updateWindow ref="updata"></updateWindow>
		<zy-popup ref="popup" type="dialog" :title="$t('my.set.exit')" @confirm="goLoginOut">
			{{$t('my.set.exitInfo')}}
		</zy-popup>
	</view>
</template>

<script>
	import {
		logout
	} from "@/api/index.js"
	import updateWindow from '@/uni_modules/e-updateModel/components/e-updateModel/e-updateModel.vue'
	import socket from "@/common/socket.js"; //引入websocket文件
	export default {
		components: {
			updateWindow
		},
		data() {
			return {
				cellList1: [{
						iconfont: "iconfont icon-banben",
						text: this.$t('my.set.version'),
						iconStyle: "color:#ffff7f;font-size:60rpx",
						sufText: uni.getStorageSync('version').version,
					}, {
						iconfont: "iconfont icon-ziyuan1",
						text: this.$t('my.set.blueTooth'),
						url: "./getBlueTooth",
						iconStyle: "color:#409EFE;font-size:60rpx",
						sufText: '',
						sufIcon: "iconfont icon-xiangyou",
					},
					{
						iconfont: "iconfont icon-duoyuyan",
						text: this.$t('my.set.lang'),
						url: "./lang",
						iconStyle: "color:#2B9939;font-size:60rpx",
						sufText: '',
						sufIcon: "iconfont icon-xiangyou",
					},
				],
				cellList2: [{
					iconfont: "iconfont icon-tuichu1",
					text: this.$t('my.set.exit'),
					iconStyle: "color:red",
					sufIcon: "iconfont icon-xiangyou",
				}],
				type: "group"
			}
		},
		onShow() {
			// 获取监听蓝牙是否打开
			if (uni.getStorageSync('blueToothSwitchChecked')) {
				this.cellList1[1].sufText = this.$t('my.set.open')
			} else {
				this.cellList1[1].sufText = this.$t('my.set.close')
			}
		},
		methods: {
			// 单元格点击事件
			clickListHandler(e) {
				if (e.index == 0) {
					this.$refs.updata.updateVersion()
				}
			},
			// 退出事件
			clickGroupHandler(e) {
				if (e.index == 0) {
					this.$refs.popup.open()
				}
			},
			// 退出事件
			goLoginOut() {
				logout().then((res) => {
					this.$refs.popup.close()
					uni.reLaunch({
						url: "../Index/index"
					})
					uni.removeStorage({
						key: 'token',
					})
					uni.removeStorage({
						key: 'loginData',
					})
					socket.closeWebsocket()
					// let arr = uni.getStorageSync("procedureData")
					// for (var i = 0; i < arr.length; i++) {
					// 	arr[i].switch = false
					// }
					// uni.setStorageSync("procedureData", arr)
				}).catch((res) => {
					uni.showToast({
						title: res.message,
						icon: "none",
						duration: 3000
					})
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.loginOut {
		height: 45px;
		line-height: 45px;
		font-size: 16px;
		background-color: #fff;
		text-align: center;
	}

	.iconfont {
		color: red;
	}

	.leftIconStyle {
		color: red;
	}
</style>